package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type QuickReply struct {
	ID         string `json:"id"  gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	MerchantID string `json:"merchant_id" gorm:"column:merchant_id;index:idx_merchantID;type:int;size:64;comment:商户ID"`
	Text       string `json:"text" gorm:"column:text;type:string;size:255;comment:快捷回复的文本"`
	CreatedAt  int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
}

// TableName 表名称
func (QuickReply) TableName() string {
	return "quick_reply"
}

// BeforeCreate 自增id
func (t *QuickReply) BeforeCreate(tx *gorm.DB) (err error) {
	if t.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	t.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &QuickReply{})
}
